<?php
namespace app\admin\model;
use think\Model;
use app\api\model\RegionCountry;
class SellerInfo extends BaseModel
{

    protected $attributes = [
        'sup_type' => [
            1 => '渠道供应商',
            2 => '个人供应商',
            3 => '个人客户',
            4 => '网站'
        ],
        'is_deal' => [
            0 => '否',
            1 => '是'
        ],

    ];

    protected $enumCallbacks = [
        'operator' => 'getOperatorEnum',
        'country' => 'getCountryEnum',
        'model' => 'getModelEnum'
    ];
    public function getOperatorEnum()
    {
        return Operator::where('is_del', 0)->column('id as value,cname as label');
    }

    public function getCountryEnum()
    {
        return RegionCountry::column("id as value,CONCAT(cname,' (',full_name,') ') as label");
    }

    public function operator(){
        return $this->hasOne(Operator::class, 'id', 'operator');
    }

    public function ownerName(){
        return $this->hasOne(Operator::class, 'id', 'owner');
    }

    public function creatorName(){
        return $this->hasOne(Operator::class, 'id', 'creator');
    }

    public function updaterName(){
        return $this->hasOne(Operator::class, 'id', 'updater');
    }


    public function getFieldEnum($field)
    {
        return $this->getEnum($field,[],'label');
    }

    /**
     *  获取机型枚举
     */
    public function getModelEnum()
    {
        return ModelInfo::order('model_name ASC')
            ->column('id as value,model_name as label');
    }







}
